package com.baiyun.stock.controller;


import com.baiyun.stock.pojo.entity.SysUser;
import com.baiyun.stock.service.UserService;
import com.baiyun.stock.vo.req.LoginReqVo;
import com.baiyun.stock.vo.resp.LoginRespVo;
import com.baiyun.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author by baiyun
 * @Date 2024/11/26
 * @Description 定义用户处理器接口
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据用户名查询用户信息
     * @param userName
     * @return
     */
    @ApiOperation("根据用户名搜索用户")
    @ApiImplicitParams({    //name(方法入参的名称)
            @ApiImplicitParam(name = "userName",value = "用户名",required = true,dataType = "String",paramType = "path")
    })
    @GetMapping("/user/{userName}")
    public SysUser getUserByUserName(@PathVariable("userName") String userName){
        return userService.getUserByUserName(userName);
    }

    /**
     * 登录
     * @param vo
     * @return
     */
    @ApiOperation("登录接口")
    @PostMapping("/login")
    public R<LoginRespVo> login(@RequestBody LoginReqVo vo){
        R<LoginRespVo> r= this.userService.login(vo);
        return r;
    }

    /**
     * 获取验证码
     * @return
     */
    @ApiOperation("获取验证码")
    @GetMapping("/captcha")
    public R<Map> getCaptchaCode(){
        return userService.getCaptchaCode();
    }
}
